#!/bin/bash
#测试工具安装
install_install_netperf(){
    if [[ -e '/usr/local/bin/netperf' ]];then
        red_z_green_z "已安装[ netperf ],无需重新安装,如需重新安装请删除--->" "[ rm -f /usr/local/bin/netperf ]"
    else
        if [[ -d "$source_netperf_dir" ]];then

            red_z_green_z "执行命令--->" "[ mkdir -p $install_netperf_dir ]"
            rm -rf ${install_netperf_dir}
            red_z_green_z "执行命令--->" "[ cp -rf ${source_netperf_dir} $install_netperf_dir ]"
            cp -rf ${source_netperf_dir} $install_netperf_dir
            chmod -R 777 $install_netperf_dir/*
            pushd $install_netperf_dir
            ./configure
            chek_status "$?" "预编译"
            make 
            chek_status "$?" "编译"
            make install
            chek_status "$?" "安装"
            install_status '/usr/local/bin/netperf' netperf
        else
            red_bg "找不到源码文件: $source_netperf_dir"
        fi
    fi
}
install_install_stream(){
    if [[ -d "${source_stream_dir}" ]];then
        cp -rf ${source_stream_dir} ${installer_dir}/
        if [[ -d "${install_stream_dir}" ]];then
            gcc -O3 -fopenmp -o stream stream.c
            chek_status "$?" "stream安装" 
        else
            red_bg "找不到文件夹: ${install_stream_dir}"
        fi
    else
        red_bg "找不到文件夹: ${source_stream_dir}"
    fi
}
install_install_iozone(){
    if [[ -e '/usr/bin/iozone' ]];then
        green_zt '已安装,如需重新安装请删除文件--->[ rm -f /usr/bin/iozone ]'
    else
    		rm -rf $install_iozone_dir
    		mkdir -p $install_iozone_dir
    		cp -rf ${source_iozone_dir}  ${install_iozone_dir}
    		pushd ${work_iozone_dir}
    		if [[ "$Framework" == 'x86_64' ]];then
    		    Framework='AMD64'
    		fi
    		make linux-${Framework}
    		chek_status "$?" "Iozone安装" 'q'
    		rm -f /usr/bin/iozone
    		ln -s ${work_iozone_dir}/iozone /usr/bin/iozone
	fi
	if [[ "$mode" == "auto" ]];then
			echo -e "使用默认参数"	
	else
		input "[ iozone ]安装完成,是否进入测试环节[y/n],默认[ y ]" t
	fi
	input_check "$t" "进入iozone测试" "y" t
    	if [[ "$t" == 'y' ]];then
    	    test_iozone
    	fi
}
install_install_unixbench_(){
    if [ -f '/usr/bin/gcc' ];then
		red_z_green_z '已安装------>' "[ gcc ]"
		if [[ ! -d "$source_unixbench_dir" ]];then
			echo -e "找不到目录: $source_unixbench_dir"
		else
		    rm -rf ${install_unixbench_dir}
			mkdir -p ${install_unixbench_dir}
    			red_z_green_z '正在复制源码-->' "cp -rf $source_unixbench_dir ${install_unixbench_dir}"
			cp -rf ${source_unixbench_dir} ${install_unixbench_dir}
			red_z_green_z "进入目录--->" "[ $work_unixbench_dir ]"
			pushd $work_unixbench_dir
			chmod -R 777 ${install_unixbench_dir}/*
		    chek_status "$?" "安装--->[ UnixBench ]" 'q'
		    input "是否立即进入[ UnixBench ]测试[y/n],默认 [ y ]" t_up
		    input_check "$t_up" "立即进入测试" 'y' t_up
		    if [[ "$t_up" == 'y' ]];then
		        test_UnixBench "$new"
		    fi
		fi
	else
		red_bg 'unixbench安装: 请先安装[ apt install gcc ]'
	fi
}
install_install_ltp(){
    green_zt "检测网络..."
    ping baidu.com -c 3  > /dev/null
    if [[ "$?" -eq 0 ]];then
        service_install 'automake'
        net=0
    fi
    if [[ -e '/usr/bin/automake' ]];then
        net=0
    fi
    if [[ ! -f "$ltp_file" ]];then
        red_bg "找不到文件---> [ $ltp_file ]"
        exit 2
    fi
    if [[ -z "$ltp_install_dir" ]];then
        ltp_install_dir=/spzx/ltp
    fi
    if [[ $ltp_install_dir != '/' ]];then
        rm -rf $ltp_install_dir
    fi
    mkdir -p $ltp_install_dir
    
    cp -rf $ltp_dir ${ltp_install_dir}
    pushd ${ltp_install_dir}
    
    if [[ "$net" -eq 0 ]];then
        make autotools
    fi
    
    ./configure
    chek_status "$?" "预编译"

    make
    chek_status "$?" "编译"

    make install
    chek_status "$?" "编译安装"
}
install_install_glmark2(){
    Check_Network 'baidu.com'
    if [[ -e '/usr/bin/apt' ]];then
        install='sudo apt install -y '
    elif [[ -e '/usr/bin/yum' ]];then
        install='sudo yum install -y '
    else
        red_bg "无法判断当前包管理器"
    fi
    mkdir -p ${install_glmark2_dir}
    service_install 'git g++ build-essential pkg-config unar libx11-dev libgl1-mesa-dev libjpeg-dev libpng-dev 
    libpng12-* libpng15-* libgbm*  mirclient libsdl2-mixer-2.0-0 libsdl2-image-2.0-0 libsdl2-2.0-0'
    red_z_green_z "执行命令: " "cp -rf ${source_glmark2_dir} ${installer_dir}"
    cp -rf ${source_glmark2_dir} ${installer_dir}
    if [[ -d "${install_glmark2_dir}" ]];then
        chmod -R 777 ${install_glmark2_dir}/*
        pushd ${install_glmark2_dir}
        ./waf configure --with-flavors=x11-gl
        cpus=`cat /proc/cpuinfo  | grep processor | wc -l`
        ./waf build -j $cpus
        sudo ./waf install
        chek_status "$?" "安装[ Glmark2 ]" 'q'
        input '是否立即进入测试--[ y/n ],默认-->[ y ]' lo
        input_check "$lo" "立即进入测试" 'y' lc
        if [[ "$lc" == 'y' ]];then
            glmark2
        fi
    fi
}
